// pages/qualityControl/controlRecord/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array3: [],
    value3:0,
    startTime:'',
    endTime:"",
    arr1:[],
    arr2:[],
    code:"",
    now:"",
    arr3:[],
    arr4:[]
  },
  toDetail(e){
    console.log(e)
    let item =  e.currentTarget.dataset.item
    let self = this;
    wx.navigateTo({
      url: './detail/index',
      success:function(res){
        res.eventChannel.emit('toredcord',{item:item,code:self.data.array3[self.data.value3],startTime:self.data.startTime,endTime:self.data.endTime})
      }
    })
  },
  getequiment(){
    this
    .axios
    .custom("AllInstalledProducts", "serialOrLotNumbers", {
      id: this.Store.getItem("userid"),
    })
    .then((result) => {
      console.log(result);
      this.setData({
        array3:result.data,
        code:result.data[0]
      })  
    })
    .catch((err) => {
      self.$notify(err.data.msg, "error");
    });
  },
  bindDateChange: function (e) {
    this.setData({
      startTime: e.detail.value
    })
},
bindDateChangeStart(e){

},
loadData() {
  let self = this;

  let param={
    startTime:self.data.startTime,
    endTime:self.data.endTime,
    code:self.data.code
  }
console.log(param)
  self
    .axios
    .query("QcProjectCategory", {}, param)
    .then(function (response) {
      let arr1=[]
      let arr2=[]
      let arr3=[]
      let arr4=[]
      response.data.rows.forEach(e=>{

        if(e.qcPeriod=='日检'){
          arr1.push(e)
        }else if(e.qcPeriod=='月检'){
          arr2.push(e)
        }
        else if(e.qcPeriod=='季检'){
          arr3.push(e)
        }
        else if(e.qcPeriod=='年检'){
          arr4.push(e)
        }
      })
      self.setData({
        arr1:arr1,
        arr2:arr2,
        arr3:arr3,
        arr4:arr4
      })
      console.log(response)
    })

},
  bindDateChangeTwo: function (e) {
    this.setData({
        endTime: e.detail.value
    })
    this.loadData()
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    
    this.setData({
      now:this.getTime(new Date())
    })
this.getequiment()
  },
  getTime(time){
    let str = new Date(time);
    let year = str.getFullYear()
    let month = (str.getMonth()+1)<10?0+""+(str.getMonth()+1):(str.getMonth()+1)
    let date = str.getDate()<10?0+""+str.getDate():str.getDate()
    return year+'-'+month+'-'+date

  },
  bindPicker3Change: function(e) {
    this.setData({
        code:this.data.array3[e.detail.value]
    })
    this.equipChange()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})